package com.hs.room.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.Update
import com.hs.room.model.archive.ArchiveChange
import kotlinx.coroutines.flow.Flow

@Dao
interface ArchiveChangeDao {

    @Insert
    suspend fun insert(d: ArchiveChange)

    @Update
    suspend fun update(d: ArchiveChange): Int

    @Query("SELECT * FROM archive_change_log where :name = archiveName")
    fun selectByName(name: String): ArchiveChange

    @Query("SELECT * FROM archive_change_log")
    fun getAll(): Flow<List<ArchiveChange>>

    @Query("SELECT * FROM archive_change_log ORDER BY localId LIMIT :limit OFFSET :offset ")
    fun get(limit: Int, offset: Int):  Flow<List<ArchiveChange>>

    @Query("SELECT count(*) FROM archive_change_log")
    fun count(): Int

    @Delete
    suspend fun delete(d: ArchiveChange)

}